<!DOCTYPE html>
<html xmlns:th="http://www.w3.org/1999/xhtml">
<head th:replace="weixin/_fragments :: head(~{::title})">
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>抢单页面</title>
    <!-- 最新版本的 Bootstrap 核心 CSS 文件 -->
    <link rel="stylesheet" href="../../static/css/bootstrap.min.css"/>
    <link rel="stylesheet" href="../../static/lib/bootstrapValidator/css/bootstrapValidator.min.css"/>
</head>
<body style="background-color: #31B0D5;">
<div style="margin-left: 8rem;">
    <ul class="nav nav-tabs">
        <li role="presentation" class="active"><a href="#" th:href="@{/meetingGrab/grab(uid=${uid})}">抢单</a></li>
        <li role="presentation"><a href="#" th:href="@{/meetingGrab/grabed(uid=${uid})}">我的抢单</a></li>
    </ul>
</div>
<div class="container well well-sm" style="margin-top: 3.125rem;">
    <div class="row">
        <div class="col-xs-9">
            共有<span th:text="${pageInfo.total}">3</span>场讲座邀请等你来抢
        </div>
        <div class="col-xs-3" id="mtypes" th:attr="data-uid=${uid}" th:fragment="mtypes">
            <div class="dropdown">
                <button class="btn btn-default dropdown-toggle" type="button" id="dropdownMenu1" data-toggle="dropdown" aria-haspopup="true" aria-expanded="true">
                    讲座类别
                    <span class="caret"></span>
                </button>
                <ul class="dropdown-menu" aria-labelledby="dropdownMenu1">
                    <li th:each="mt : ${meetingTypes}">
                        <a href="#" th:href="@{/meetingGrab/grab(uid=${uid},tid=${mt.id})}" th:text="${mt.tname}">物理领域</a>
                    </li>
                    <!--/*-->
                    <li><a href="#">Another action</a></li>
                    <li><a href="#">Something else here</a></li>
                    <li role="separator" class="divider"></li>
                    <li><a href="#">Separated link</a></li>
                    <!--*/-->
                </ul>
            </div>
        </div>
    </div>
    <div>
        <ul class="list-group" th:each="meeting : ${pageInfo.list}">
            <li class="list-group-item">
                <div class="row">
                    <div class="col-xs-9">
                        <ul class="list-group">
                            <li class="list-group-item"><a href="#" th:href="@{/meetingPublish/publishedDetail(id=${meeting.id})}" th:text="${meeting.mtitle}">量子力学的设计</a></li>
                            <li class="list-group-item"><span th:text="${meeting.mcode}">20181010001</span>/<span th:text="${meeting.mtime}">2018/10/10 12:40</span></li>
                        </ul>
                    </div>
                    <div class="col-xs-3">
                        <button class="btn btn-sm btn-danger" style="margin-top: 2rem;" th:attr="data-uid=${uid},data-mid=${meeting.id}" onclick="grab(this)">抢单</button>
                    </div>
                </div>
            </li>
            <!--/*-->
            <li class="list-group-item">
                <div class="row">
                    <div class="col-xs-9">
                        <ul class="list-group">
                            <li class="list-group-item">量子力学的设计</li>
                            <li class="list-group-item"><span>清华大学</span>/<span>2018-10-10 12:45:23</span></li>
                        </ul>
                    </div>
                    <div class="col-xs-3">
                        <button class="btn btn-sm btn-danger" style="margin-top: 2rem;">抢单</button>
                    </div>
                </div>
            </li>
            <li class="list-group-item">
                <div class="row">
                    <div class="col-xs-9">
                        <ul class="list-group">
                            <li class="list-group-item">量子力学的设计</li>
                            <li class="list-group-item"><span>清华大学</span>/<span>2018-10-10 12:45:23</span></li>
                        </ul>
                    </div>
                    <div class="col-xs-3">
                        <button class="btn btn-sm btn-danger" style="margin-top: 2rem;">抢单</button>
                    </div>
                </div>
            </li>
            <!--*/-->
        </ul>
    </div>
    <div>
        <nav aria-label="Page navigation">
            <ul class="pager">
                <li class="previous" th:if="${pageInfo.pageNum} ne '1'">
                    <a href="#" th:href="@{/meetingGrab/grab(uid=${uid},pageNum=${pageInfo.prePage})}"><span aria-hidden="true">&larr;</span> 上一页</a>
                </li>
                <li class="next" th:if="${pageInfo.pageNum} ne ${pageInfo.pages}">
                    <a href="#" th:href="@{/meetingGrab/grab(uid=${uid},pageNum=${pageInfo.nextPage})}">下一页 <span aria-hidden="true">&rarr;</span></a>
                </li>
            </ul>
        </nav>
    </div>
    <div id="modal01" class="modal fade bs-example-modal-sm" tabindex="-1" role="dialog">
        <div class="modal-dialog modal-sm" role="document">
            <div class="modal-content">
                <strong>提示：</strong></br>
                <p>网络异常请稍后重试！</p>
            </div>
        </div>
    </div>
    <div id="modal02" class="modal fade bs-example-modal-sm" tabindex="-1" role="dialog">
        <div class="modal-dialog modal-sm" role="document">
            <div class="modal-content">
                <strong>提示：</strong></br>
                <p>恭喜您，抢单成功！</p>
            </div>
        </div>
    </div>

    <div id="confirm" class="modal fade" tabindex="-1" role="dialog">
        <div class="modal-dialog" role="document">
            <div class="modal-content">
                <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
                    <h4 class="modal-title">确认抢单?</h4>
                </div>
                <div class="modal-body">
                   <textarea id="remark" rows="3" cols="50" placeholder="备注（150字以内）"></textarea>
                </div>
                <div class="modal-footer">
                    <button type="button" class="btn btn-default" data-dismiss="modal" onclick="history.go(0)">取消</button>
                    <button type="button" class="btn btn-primary" onclick="submit()">确定</button>
                </div>
            </div><!-- /.modal-content -->
        </div><!-- /.modal-dialog -->
    </div><!-- /.modal -->
</div>

<!--/*/<th:block th:replace="weixin/_fragments :: script">/*/-->
<script src="../../static/jquery/jquery-3.4.1.min.js" type="text/javascript"></script>
<script src="../../static/js/bootstrap.min.js" type="text/javascript"></script>
<script src="../../static/lib/bootstrapValidator/js/bootstrapValidator.min.js" type="text/javascript"></script>

<!--/*/</th:block>/*/-->
<!--<script src="http://res.wx.qq.com/open/js/jweixin-1.6.0.js" type="text/javascript"></script>-->
<script>
    $(function () {
        // 加载所有订单类别
        var uid = $('#mtypes').data("uid");
        $('#mtypes').load(/*[[@{/meetingType/findAll}]]*/ "/meetingType/findAll?target=grab&uid="+uid);
    })


    var formData = new FormData();
    function grab(obj) {
        var mid = $(obj).data("mid");// 讲座编号
        var uid = $(obj).data("uid"); // 抢单人员id
        formData.append("mid", mid);
        formData.append("uid", uid);
        $('#confirm').modal('show');
    }

    function submit() {
        var url ="/meetingGrab/grab";
        var remark = $('#remark').val();
        formData.append("remark", remark);
        $.ajax({
            url: url,
            type: 'POST',
            data: formData,                    // 上传formdata封装的数据
            dataType: 'JSON',
            cache: false,                      // 不缓存
            processData: false,                // jQuery不要去处理发送的数据
            contentType: false,                // jQuery不要去设置Content-Type请求头
            success:function (msg) {           //成功回调
                $('#confirm').modal('hide');

                if (msg == "1") {
                    $("#modal01").modal("show"); // 抢单失败
                } else if (msg == "2") {
                    $("#modal02").modal("show"); // 抢单成功
                    setTimeout(function () {
                        window.location.reload();
                    }, 1000);
                }
            }
        });
    }

</script>
</body>
</html>
